<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/百度.css">
    <style>
        #loadingCanvas {
            position: absolute;
            top: 0;
            left: 0;
            z-index: 3;
        }

        .input-box {
            position: relative;
        }
    </style>
</head>

<body>
    <form action="server.html">
        <div id="box">
            <div class="input-box" id="logo">用户名账号登录</div>
            <div class="input-box">
                <input type="text" placeholder="手机/邮箱" name="user" id="user">
                <p id="user-msg"></p>
            </div>
            <div class="input-box">
                <input type="password" placeholder="密码" name="pass" id="pass">
                <p id="pass-msg"></p>
            </div>
            <div class="item-box"><input type="checkbox" checked>下次自动登录</div>
            <div class="input-box">
                <button class="btn-login">登录</button>
            </div>
            <div class="a-box">
                <a href="#">忘记密码?</a>
                <a href="#" class="right-a">短信快捷登录</a>
            </div>
            <div id="oper-box">
                <a href="#" class="code">扫码登录</a>|
                <a href="#"><img src="image/qq.png" alt=""></a>
                <a href="#"><img src="image/微博.png" alt=""></a>
                <a href="百度注册框.html" class="register">立即注册</a>
            </div>
        </div>
    </form>
    <script src="../js/jquery.min.js"></script>
    <script>
        $('body').on('click', '.btn-login', function (e) {
            e.preventDefault()
            $.ajax({
                url: '/users/login',
                success: function (data) {
                    console.log(data);
                    let { status, token } = data
                    if (status == 'OK') {
                        localStorage.token = token;
                        alert('登录成功,跳转到管理页面')
                        location.href = `index.html`

                    } else {
                        alert('登录失败')
                    }
                },
                data: {
                    username: $('#user').val(),
                    userpass: $('#pass').val()
                },
                type: 'post'
            })
        })
    </script>
</body>

</html>